package com.crm.common.result;

import lombok.Data;

import java.io.Serializable;

/**
 * 后端统一返回结果
 * @author 毛腾自学Java
 * @param <T>
 */
@Data
public class ResultVO<T> implements Serializable {
	/**
	 * 编码：1成功，0和其它数字为失败
	 */
	private Integer code;
	/**
	 * 错误信息
	 */
	private String msg;
	/**
	 * 数据
	 */
	private T data;

	public static <T> ResultVO<T> success() {
		ResultVO<T> result = new ResultVO<>();
		result.code = 200;
		result.msg = "操作成功";
		return result;
	}

	public static <T> ResultVO<T> error() {
		ResultVO<T> result = new ResultVO<>();
		result.code = 200;
		result.msg = "ERROR";
		return result;
	}

	public static <T> ResultVO<T> success(T object) {
		ResultVO<T> result = new ResultVO<>();
		result.data = object;
		result.code = 200;
		result.msg = "操作成功";
		return result;
	}

	public static <T> ResultVO<T> error(String msg) {
		ResultVO<T> result = new ResultVO<>();
		result.msg = "操作成功";
		result.code = 500;
		return result;
	}

}
